<?php

use think\facade\Route;

Route::rule('api/:alias/[:method]', function () {
    $alias = plugin_alias_get();
    $method = plugin_method_get();
    $model = plugin_info_get($alias);
    if (!$model) {
        return msg("error", "该api不存在");
    }
    $class = "api\\{$model['class']}\\App";
    if (!class_exists($class)) {
        return msg("error", "该api类不存在");
    }
    $app = new $class();
    if (!method_exists($app, $method)) {
        return msg("error", "该api不存在" . $method . "方法");
    }
    $app->initialize($model);
    return $app->$method();
});


Route::get('doc/:alias', 'Doc/index')->middleware(\app\middleware\LoadConfig::class);
